# -*- coding: utf_8 -*-
# @Time : 2021/9/7 0007 10:23
# @Author : lyw
# @Remark : 门禁出入记录排序
class Serial(object):

    def __init__(self, data_list: int, page_size, current_page):
        self.start = 0
        self.end = 0
        self.max_page = 0
        self.__data_list = data_list
        self.page_size = page_size
        self.current_page = current_page
        self.__default_page = 1
        if not page_size or page_size == 0:
            self.page_size = 10
        if not current_page or current_page == 0:
            self.current_page = 1
        # 判断是不是列表或者是个空的目录
        if self.__data_list > 0:
            # 获取最后一页

            if int(self.__data_list) <= int(self.page_size):
                self.page_size = self.__data_list
            self.max_page, i = divmod(int(self.__data_list), int(self.page_size))
            if i > 0:
                self.max_page += 1
            # 生成分页的开始和结束
            self.start = (int(self.current_page) - 1) * int(self.page_size)
            self.end = int(self.current_page) * int(self.page_size)
            # 判断是不是超出范围 然后然后最后一页
            if int(self.current_page) > int(self.max_page):
                self.start = (int(self.max_page) - 1) * int(self.page_size)
                self.end = int(self.max_page) * int(self.page_size)
        # self.run_list = self.run()
        # self.start = self.start + 1

    def __iter__(self):
        return self

    def __next__(self):
        self.start += 1
        return self.start


if __name__ == '__main__':
    ser = Serial(0, 10, 2)
    iter_obj = iter(ser)
    print(next(iter_obj))
    print(next(iter_obj))
    print(next(iter_obj))
    print(next(iter_obj))
